<template>
<div>
  <component :is="currentView" keep-alive :keyMap="keyMap" :parentDesignerData='desigerData' :inputParams='params' ></component>
</div>
</template>
<script>
import graphComp from 'views/graph/designer.vue'
import api from 'api/device.js'
import {
  RES_ITEM_FLOAT,
  RES_ITEM_STR,
  RES_ITEM_LOG,
  RES_ITEM_UINT,
  RES_ITEM_TEXT
} from 'common/resTypeEnum'
export default {
  props: {
    devId: {
      type: String,
      default: function() {
        return '';
      }
    },
    devType: {
      type: Number,
      default: function() {
        return 2;
      }
    }
  },
  watch:{
    devId(){
      this.show();
    }
  },
  data() {
    return {
      currentView: graphComp,
      keyMap: {
        editable: 'false'
      },
      desigerData: {},
      params: {}
    };
  },
  methods: {
    show() {
      api.queryByItemid(this.devId).then((response) => {
        var iteminfo = response.data;
        this.params = {
          itemid: this.devId,
          name:iteminfo[0].name,
          units:iteminfo[0].units,
          valueType:iteminfo[0].value_type
        };
        let grsNo = 'item'
        if(!(RES_ITEM_FLOAT == this.params.valueType || RES_ITEM_UINT == this.params.valueType) ){
          grsNo = 'item-table'
          this.params['graphType'] = 'item-table'
        }
        this.desigerData = {
          grsNo: grsNo
        };
        this.currentView = graphComp;
      }).catch((err) =>{
          console.error(err);
      });
    }
  },
  mounted() {
    this.show();
  },
  components: {
    graphComp
  }
};
</script>
